package week2;

public class Addsum {

        public static void main(String[] args) {
            whileSum();
            doWhileSum();
            forSum();
            isSuShu();
        }
        public static void whileSum() {
            int i = 1, sum = 0;
            while (i <= 100) {
                sum += i;
                i++;
            }
            System.out.println("sum=" + sum);
        }

        public static void doWhileSum() {
            int i = 1, sum = 0;
            do {
                sum += i;
                i++;
            } while (i <= 100);
            System.out.println("sum=" + sum);
        }
        public static void forSum(){
            int i,sum=0;
            for (i=1;i<=100;i++)
            {
                sum+=i;
            }
            System.out.println("sum="+sum);
        }
        public static void isSuShu()
        {
            int num=18,i;
            boolean flag=true;
            for (i=2;i<num;i++)
            {
                if(num%i==0)
                {
                    flag=false;
                    break;
                }
            }
            if(flag){
                System.out.println(num+"是素数！");
            }else {
                System.out.println(num+"不是素数！");
            }
        }

}
